﻿#include "invalidsearch.h"

InvalidSearch::InvalidSearch(Map *map0):currentPoint(-1,-1)
{
    setMap(map0);
    distance=0;
    stepCount=0;
}
void InvalidSearch::setMap(Map *map0)
{
    map=map0;
    currentPoint=map->getStart();
}

void InvalidSearch::setDistance(int distance0)
{
    distance=distance0;
}

void InvalidSearch::step() 
{
    Point pre=currentPoint;
    Point dp=map->getEnd()-currentPoint;
    if(dp.x>0){
        currentPoint.x++;
    }else if (dp.x<0)
    {
        currentPoint.x--;
    }
    if(dp.y>0){
        currentPoint.y++;
    }else if (dp.y<0)
    {
        currentPoint.y--;
    }
    map->output(currentPoint,pre,PATH,"Step:"+QString::number(++stepCount));
//    qDebug()<<"("<<currentPoint.x<<","<<currentPoint.y<<")";
    if(currentPoint==map->getEnd()){
        isFinished=1;
        emit finished(true);
    }else{
    emit completed(true);
    }
}

void InvalidSearch::Continuous() 
{
    while(!isFinished){
    step();
    }
}

void InvalidSearch::stop() 
{
    ;
}
